<template>
  <div class="page-content">
    <div>
      <ul>
        <li></li>
      </ul>
      <div>
        <a href="javascript:void(0)" @click="studentAdd()">添加学生</a>

        <table class="user-table">
          <thead>
          <tr>
            <th>账号</th>
            <th>姓名</th>
            <th>状态</th>
          </tr>
          </thead>
          <tbody v-for="s in students" :key="s.stuId">
          <tr>

            <td v-text="s.stuNumber">1</td>
            <td v-text="s.stuName">小明</td>
            <td v-text="s.stuStatus==1?'正常':'禁用'">123456</td>
            <td class="admin-manage">
              <a  href="javascript:void(0)" @click="studentRevise(s.stuId)">
                修改信息
              </a>
            </td>
            <td class="admin-manage">
              <a  href="javascript:void(0)" @click="studentPasswordRevise(s.stuId)">
                修改密码
              </a>
            </td>
            <td>
              <a  href="javascript:void(0)" @click="studentStatusRevise(s.stuId)"  v-text="s.stuStatus==0?'启用':'禁用'">

              </a>
            </td>


          </tr>

          </tbody>
        </table>


      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "studentList",
  data() {
    return {
      students :null
    }

  },
  created() {
    this.initStudent();
  },
  methods:{
    initStudent() {
      const that = this;
      that.axios.get("/api/admin_stu_list").then(({ data }) => {
        this.students = data.data;
      });
    },
    studentRevise(id){
      this.$router.push({ path: "/StudentRevise/"+id });
    },
    studentPasswordRevise(id){
      this.$router.push({ path: "/StudentPasswordRevise/"+id });
    },
    studentStatusRevise(id){
      const that = this;
      that.axios.post("/api/stu_status/"+id).then(({ data }) => {
        if (data.flag) {
          that.$message.success("修改成功");
          that.initStudent();
        } else {
          that.$message.error(data.message);
        }
      });
    },
    studentAdd(){
      this.$router.push({ path: "/StudentAdd"});
    }
  }
}
</script>

<style scoped>

</style>
